<template>
	<uni-popup ref="popupRef" type="bottom" background-color="#F9F6F6" borderRadius="24rpx 24rpx 0rpx 0rpx" :is-mask-click="false">
		<view class="refuse_pop">
			<view class="pop_title_box">
				<view class="pop_title">
					<text>宠物信息</text>
					<text class="pets_num">（{{ petsList.length }}只）</text>
				</view>
				<uni-icons @click="handleClosePop()" class="closeempty_icon" type="closeempty" size="26"></uni-icons>
			</view>
			<view class="pets_list_box">
				<view class="pets_item_box" v-for="item in petsList" :key="item.id">
					<image :src="item.petAvatar" class="pet_img"></image>
					<view class="pets_info_box">
						<view class="pets_name_sex">
							<view class="pets_name">{{ item.petNickName }}({{ getPetTypeText(item.type) }})</view>
							<image class="pets_sex" :src="getSex(item.sex)"></image>
						</view>
						<view class="pets_character_box">
							<!--							{{ item.variety }} | {{ birthToAgeDiff(item.birthday) }}｜{{ item.ifVaccinate == 0 ? "已" : "未" }}接种｜{{ item.ifNeuter == 0 ? "已" : "未" }}绝育-->
							<template v-if="item.variety || item.typeName">
								{{ item.variety ? item.variety + " | " : item.typeName + " | " }}
							</template>
							{{ item.sex == 2 ? "" : item.sex == 1 ? "母 | " : "公 | " }}
							{{ birthToAgeDiff(item.birthday) }}| {{ item.ifVaccinate == 1 ? "未免疫" : "已免疫" }} |
							{{ item.ifNeuter == 1 ? "未绝育" : "已绝育" }}
						</view>
						<view class="pets_tips_box">
							<view :class="[item.isShow ? 'pets_tips' : 'pets_tips_overflow']">{{ item.personality }}</view>
							<view v-if="item.personality.length > 36" class="toggle_btn" @click="handleToggle(item)">
								{{ item.isShow ? "收起" : "展开" }}
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</uni-popup>
</template>

<script setup>
import { ref, reactive } from "vue";
import { birthToAgeDiff } from "@/hooks/useFunction";

let petsList = reactive([]);
let popupRef = ref();
const handleOpenPop = (info) => {
	Object.assign(petsList, JSON.parse(info));
	console.log(petsList);
	popupRef.value.open();
};
const handleClosePop = () => {
	popupRef.value.close();
};
const handleToggle = (item) => {
	item.isShow = !item.isShow;
};
const getPetTypeText = (type) => {
	switch (type) {
		case 0:
			return "猫";
		case 1:
			return "狗";
		default:
			return "其他";
	}
};
const getSex = (sex) => {
	switch (sex) {
		case 0:
			return "https://xjs-oss-prod.oss-cn-shenzhen.aliyuncs.com/xjs-static/icon-35.png";
		case 1:
			return "https://xjs-oss-prod.oss-cn-shenzhen.aliyuncs.com/xjs-static/icon-36.png";
		default:
			return "";
	}
};

defineExpose({
	handleOpenPop,
	handleClosePop
});
</script>

<style scoped lang="scss">
.refuse_pop {
	max-height: 90vh;
	overflow-y: auto;
	width: 100%;
	background: #f9f6f6;
	border-radius: 24rpx 24rpx 0rpx 0rpx;
	padding: 0 32rpx 68rpx 32rpx;
	box-sizing: border-box;
	position: relative;
	line-height: 1;

	.pop_title_box {
		display: flex;
		justify-content: space-between;
		position: sticky;
		padding-top: 48rpx;
		padding-bottom: 50rpx;
		top: 0;
		left: 0;
		background: #f9f6f6;

		.pop_title {
			font-weight: bold;
			font-size: 40rpx;
			color: #1b2120;

			.pets_num {
				font-size: 30rpx;
				color: #7c807f;
			}
		}

		.closeempty_icon {
			color: #1b2120;
			font-weight: bold;
		}
	}

	.pets_item_box {
		width: 100%;
		background: #ffffff;
		border-radius: 24rpx;
		padding: 32rpx;
		box-sizing: border-box;
		margin-bottom: 24rpx;
		display: flex;
		flex-direction: row;

		.pet_img {
			width: 120rpx;
			height: 120rpx;
			border-radius: 50%;
		}

		.pets_info_box {
			display: flex;
			flex-direction: column;
			margin-left: 16rpx;
			width: calc(100% - 120rpx - 16rpx);

			.pets_name_sex {
				display: flex;
				flex-direction: row;
				align-items: center;
				font-size: 32rpx;
				color: #1b2120;
				margin-top: 16rpx;

				.pets_name {
					margin-right: 16rpx;
				}

				.pets_sex {
					width: 36rpx;
					height: 36rpx;
				}
			}

			.pets_character_box {
				display: flex;
				align-items: center;
				margin-top: 16rpx;
				font-size: 24rpx;
				color: #7c807f;
			}

			.pets_tips_box {
				position: relative;

				.pets_tips_overflow {
					line-height: 1.6;
					font-size: 26rpx;
					color: #7c807f;
					margin-top: 24rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
				}

				.pets_tips {
					font-size: 26rpx;
					color: #7c807f;
					margin-top: 24rpx;
					line-height: 1.6;
				}

				.toggle_btn {
					background: #ffffff;
					font-size: 26rpx;
					color: #ff6084;
					margin-top: 24rpx;
					position: absolute;
					right: 0;
					bottom: 0;
				}
			}
		}
	}
}
</style>
